<%--
  Created by IntelliJ IDEA.
  User: zzz
  Date: 2020/2/12
  Time: 10:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<div class="card">
    <div class="card-body p-0">
        <form id="sendSearch">
            <input id="sendLikeName" type="text" class="form-control border-0 p-15 p-l-20 h-auto font-size-15" placeholder="请输入订单编号或订单包含商品名称...">
        </form>
    </div>
</div>

<div class="card">
    <div class="card-body" id="sendOrderTab">
        <div class="table-responsive">
            <table class="table">
                <thead>
                <tr>
                    <th scope="col">订单号</th>
                    <th scope="col">下单时间</th>
                    <th scope="col">订单金额</th>
                    <th scope="col">支付方式</th>
                    <th scope="col">状态</th>
                    <th class="text-right" scope="col">操作</th>
                </tr>
                </thead>
                <tbody id="sendOrderList">

                </tbody>
            </table>
        </div>

        <nav aria-label="Page navigation example" class="mb-3">
            <ul id="sendPaging" class="pagination justify-content-center">

            </ul>
        </nav>

    </div>
</div>
</body>
</html>
<script>
    var sendOrderPage = 1;
    $(function () {
        if(${requestScope.orderTarget == 'sendOrder'}){
            sendOrderPage = ${requestScope.pageNo};
        }
        getSendOrder(sendOrderPage);
        $("#SendSearch").submit(function () {
            getSendOrder(1);
            return false;
        });
    });

    function getSendOrder(page) {
        $.ajax({
            url : "${APP_PATH}/myOrders/findOrder",
            method : "GET",
            data : {
                pageNo : page,
                likeName : $("#sendLikeName").val(),
                methodName : 'getSendOrder',
                otype : 1
            },
            beforeSend: function () {
                var orderContent = "";
                orderContent += '<div style="margin-left: 538px;" class="spinner-grow text-info" role="status">';
                orderContent += '<span class="sr-only"></span>';
                orderContent += '</div>';
                $("#sendOrderList").html(orderContent);
            },
            success : function (result) {
                if(result.success){
                    var orderList = result.data.datas;
                    var orderContent = "";
                    var pageContent = result.data.pageContent;
                    sendOrderPage = result.data.pageNo;
                    $("#sendOrderBadge").html(result.data.count);
                    if(orderList.length == 0){
                        $("#sendOrderList").html('<tr><td colspan="6"><div style="margin-left:450px; margin-top: 150px; margin-bottom: 100px;"><img  src="${APP_PATH}/img/noorder.png" alt="..."></div><td><tr>');
                        $("#sendPaging").hide();
                    }else{
                        $("#sendPaging").show();
                        var payType = "";
                        for (var i = 0; i < orderList.length; i ++){
                            var badge = '<td><span class="badge badge-info">已发货</span></td>';
                            if(orderList[i].payType == 0){
                                payType = "货到付款";
                            }else{
                                payType = "在线支付";
                            }
                            orderContent +='<tr>';
                            orderContent +='<th scope="row">'+orderList[i].onum+'</th>';
                            orderContent +='<td>'+orderList[i].otime+'</td>';
                            orderContent +='<td>'+orderList[i].oprice.toFixed(2)+'</td>';
                            orderContent +='<td>'+payType+'</td>';
                            orderContent +=badge;
                            orderContent +='<td class="text-right">';
                            orderContent +='<div class="dropdown">';
                            orderContent +='<a href="#" class="btn btn-light btn-floating btn-icon btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';
                            orderContent +='<i class="fa fa-ellipsis-v" aria-hidden="true"></i>';
                            orderContent +='</a>';
                            orderContent +='<div class="dropdown-menu dropdown-menu-right">';
                            orderContent +='<button class="dropdown-item text-info" onclick="toOrderDetail('+orderList[i].oid+','+sendOrderPage+')" type="button">查看详情</button>';
                            orderContent +='<button class="dropdown-item text-danger" onclick="deleteOrder('+orderList[i].oid+','+orderList[i].otype+')" type="button">删除</button>';
                            orderContent +='</div>';
                            orderContent +='</div>';
                            orderContent +='</td>';
                            orderContent +='</tr>';
                        }
                        $("#sendOrderList").html(orderContent);
                        $("#sendPaging").html(pageContent);
                    }
                }
            }
        });
    }
</script>